int CopyLineFile(char const *src, char const *dest) {
if (!src || !dest) {
return COPY_ILLEGAL_ARGUMENTS;
}
FILE *src_file = fopen(src, "r");
if (!src_file) {
return COPY_SRC_OPEN_ERROR;
}
FILE *dest_file = fopen(dest, "w");
if (!dest_file) {
fclose(src_file);
return COPY_SRC_OPEN_ERROR;
}
//TODO
int result = COPY_SUCCESS;
char buffer[BUFSIZ];
char *next;
while (1) {
next = fgets(buffer, BUFSIZ, src_file);
if (!next) {
if (ferror(src_file)) {
result = COPY_SRC_READ_ERROR;
} else if (feof(src_file)) {
result = COPY_SUCCESS;
} else {
result = COPY_UNKNOWN_ERROR;
}
break;
}
if (fputs(next,dest_file) == EOF) {
result = COPY_DEST_WRITE_ERROR;
break;
} else{
result = COPY_SUCCESS;
}
}
fclose(src_file);
fclose(dest_file);
return 0;
}